﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataAccessLayer.Models;
using PresentationLayerMVC.Models;

namespace PresentationLayerMVC.Controllers
{
    public class StatelessHome : Controller
    {
        protected const int INFO_CUST        = 1;
        protected const int INFO_FAC         = 2;
        protected const int INFO_SEC         = 3;

        protected void PutUserSession(User user)
        {
            Session["LoggedUser"] = user;
        }

        protected void RemoveUserSession()
        {
            Session["LoggedUser"] = null;
        }

        protected int GetUserIdFromSession()
        {
            User user = (User)Session["LoggedUser"];
            if (user != null) return user.UserId;
            return -1;
        }

        protected void PutAppModelInSession(int info, IValueProvider value)
        {
            AppModel appInfo = (AppModel) Session["ApplicationInfo"];
            if (appInfo == null)
            {
                appInfo = new AppModel();
                Session["ApplicationInfo"] = appInfo;
            }

            if (INFO_CUST == info) appInfo.custInfo = value;
            if (INFO_FAC == info) appInfo.facilityInfo.Add(value);
            if (INFO_SEC == info) appInfo.securityInfo.Add(value);
        }

        //Thuzar's
        protected void PutProductInSession(Product productInfo)
        {
            if (productInfo != null)
                Session["ProductInfo"] = productInfo;
        }

        protected Product GetProductFromSession()
        {
            if (Session["ProductInfo"] != null)
                return Session["ProductInfo"] as Product;
            return null;
        }

        protected void PutSecurityTypeInSession(string secType)
        {
            if (secType != null)
                Session["SecType"] = secType;
        }

        protected string GetSecurityTypeFromSession()
        {
            if (Session["SecType"] != null)
                return Session["SecType"].ToString();
            return "";
        }

        protected void ClearAppInfoInSession()
        {
            Session["ApplicationInfo"] = null;
            Session["ProductInfo"] = null;
            Session["SecType"] = null;
        }
        //+++++++++++++++
    }
}